from django import forms
from rbac import models


class RolesForm(forms.ModelForm):
    class Meta:
        model = models.Role
        fields = ['title']

        widgets = {
            'title': forms.TextInput(attrs={'class': 'form-control'})
        }

    def clean_title(self):
        title = self.cleaned_data.get('title', '')
        if not title:
            self.add_error('title', '当前角色名称不能为空')
        return title
